var actcouponbill = require('../../../../xc/model/coupon_cont')
Component({
  options: {
    addGlobalClass: true,
    multipleSlots: true
  },
  /**
   * 组件的属性列表
   */
  properties: {
    nameColor:String,
    couponColor:String,
    themcolor:Object,
  },
  /**
   * 组件的初始数据
   */
  data: {
    showmore:false,
    proid:0,
    showtag:[],
    modellist:[],
  },

  /**
   * 组件的方法列表
   */
  methods: {
    couponshow(){   
      this.triggerEvent('click',  {})
    },
    showinfo(userinfo,proid){
      this.data.proid=proid
      this.setData({showmore:true})
      this.getdata();
    },
    morecoupon(){
      this.setData({showmore:!this.data.showmore})
    },
    receivecoupon(ev){
      var dataset=ev.currentTarget.dataset;
      var item=  dataset.item 
      var idx= dataset.idx
      var that = this
      
      actcouponbill.receivecoupon(item.id).then(res=>{
        var updatemodel={}
        var keyval="modellist["+idx+"]."
        if(res["status"]==1){

          
        
       
           updatemodel[keyval+"myreceivednum"]=res["obj"].myreceivednum
           updatemodel[keyval+"receivednum"]=res["obj"].receivednum
           
           
          that.setData(updatemodel)
         
          wx.showToast({
            title: '领取成功',
          })
        }
        else
        {
          if( res["status"]==-1){
            wx.showToast({
              title: res["message"],
            })
          }else if ( res["status"]==2){
            updatemodel[keyval+"receivednum"]=this.data.modellist[idx].num;
            that.setData(updatemodel)
          }
          else if ( res["status"]==3){
            updatemodel[keyval+"myreceivednum"]=this.data.modellist[idx].everyonelimit
            that.setData(updatemodel)
          }

        }

      })
     


    },
    getdata(proid){
     if(!proid){
      proid=this.data.proid
     }  
     var that= this;
    actcouponbill.procoupon(proid).then(res=>{
        
        var showtag=[]

        if(res["status"]==1){
          var modellist=[];
          if(  res["obj"]){
            modellist=res["obj"];
            var ilen =modellist.length
            for(var i=0;i<ilen;i++){
            

              if(modellist[i].cid ==1)
              {
                modellist[i].val= modellist[i].val
              }              
              modellist[i].fullmoney= modellist[i].fullmoney

              if(i<2)
              {
                var temtag=""
                if(modellist[i].hascondition==1){
                
                }
                else
                {
                  temtag+="满" +(modellist[i].fullmoney/100)+"元"
                }

                if(  modellist[i].cid==1){
                  temtag+="减" +(modellist[i].val/100)
                }
                else
                {
                  temtag+=modellist[i].val/10 +"折"
                }
                showtag.push(temtag)

              }
             


            }
          }
          else
          {

          }

          that.setData({modellist:modellist,showtag:showtag})
 
        }

    


      })
    }
  }
})
